from django.db import models
from django.contrib.auth.models  import User

class Book(models.Model):
    user      = models.ForeignKey(User)
    title     = models.CharField(max_length = 100)
    author    = models.CharField(max_length = 100)
    publisher = models.CharField(max_length = 100) 
    publication_date = models.DateField()
  
    def __unicode__(self):
        return self.title

class BookNote(models.Model):
    book             = models.ForeignKey(Book)
    chapter          = models.CharField(max_length = 100)
    page_number      = models.IntegerField()
    paragraph        = models.IntegerField()
    quotation        = models.TextField(max_length = 500)
    summerization    = models.TextField(max_length = 500)
    
    def snippet(self):
        sn = self.quotation
        lsn = sn.lower()
        if ((len(lsn) % 50 < len(lsn))):
            lsn = lsn[:50]
        sn  = lsn + '...'
        return(sn) 
    def __unicode__(self):
        return self.book.title
